package C;

import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class C32 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        System.out.println(getResult(str));
    }

    public static long getResult(String str) {
        Pattern p = Pattern.compile("(\\d+)\\$(\\d+)");

        while (true) {
            Matcher m = p.matcher(str);
            if (!m.find()) break;
            long x = Long.parseLong(m.group(1)),y = Long.parseLong(m.group(2));
            long res = x*3+y+2;
            String subStr = m.group(0);
            System.out.println(subStr+" "+x+" "+y);
            subStr = subStr.replace("$","\\$");
            System.out.println("substr="+subStr);
            str = str.replaceFirst(subStr,String.valueOf(res));
            System.out.println(str);

        }

        return Arrays.stream(str.split("#"))
                .map(Long::parseLong)
                .reduce((x, y) -> 2 * x + 3 * y + 4)
                .orElse(0L);
    }
}

